﻿using Hotel.BLL;
using Hotel.DAL;
using Hotel.Model.Shop;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShopController : ControllerBase
    {

        public ShopController(ShopBLL shopBLL)

        {
            ShopBLL = shopBLL;
        }

        public ShopBLL ShopBLL { get; }







        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="shopModel"></param>
        /// <returns></returns>
        [HttpPost]
        public int ShopAdd(ShopModel shopModel)
        {

            return ShopBLL.ShopAdd(shopModel);

        }


        /// <summary>
        /// 图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpFiles(IFormFile file)
        {

            var str = Guid.NewGuid();
            var path = Directory.GetCurrentDirectory() + @"\wwwroot\img" + str + file.FileName;

            using (FileStream fs=new FileStream(path,FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return Ok("https://localhost:7276/img"+str+file.FileName);

        }

        /// <summary>
        ///显示
        /// </summary>
        /// <param name="count"></param>
        /// <param name="page"></param>
        /// <param name="ShopName">门店名称</param>
        /// <param name="ShopType">服务范围</param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShopList(string? ShopName="", string? ShopType = "-1", int index = 1, int size = 2)
        {

            int count = 0;
            int page = 0;
            var list = ShopBLL.ShopList(out count, out page, ShopName, ShopType, index, size);
            return Ok(new { count = count, page = page, list = list });

        }





        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int ShopDel(int id)
        {


            return ShopBLL.ShopDel(id);
        }






        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ShopModel ShopAll(int id)
        {
            return ShopBLL.ShopAll(id);

        }



        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="shopModel"></param>
        /// <returns></returns>
        [HttpPut]
        public int ShopUpd(ShopModel shopModel)
        {

            return ShopBLL.ShopUpd(shopModel);
        }




        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="State"></param>
        /// <returns></returns>
        [HttpPut]
        public int UpdState(string ids, int State)
        {

            return ShopBLL.UpdState(ids, State);



        }














    }
}
